package com.demo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;

import com.module.commonui.R;
import com.tg.appcommon.android.LanguageUtils;
import com.tg.appcommon.android.ResourcesUtil;
import com.tange.base.toolkit.StringUtils;
import com.tg.appcommon.android.TGApplicationBase;

public class HibernateCountdownView extends LinearLayout {

    private ImageView mImageView;
    private TextView mTextView;
    private int mMode = 0;

    public void setRecordType(int recordType) {
        this.mMode = recordType;
    }

    public HibernateCountdownView(Context context) {
        super(context);
        initContentView(context);
    }

    public HibernateCountdownView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public HibernateCountdownView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initContentView(context);
    }


    private void initContentView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.passive_device_home_countdown, this, true);

        mImageView = view.findViewById(R.id.iv_battery);
        mTextView = view.findViewById(R.id.tv_text);

        mTextView.setVisibility(LanguageUtils.isSimChinese(TGApplicationBase.getApplicationContext())? VISIBLE : GONE);

    }


    public void setImageResource(@DrawableRes int resId){
        mImageView.setImageResource(resId);
    }


    public TextView getTextView(){
        return mTextView;
    }

    public String getText(){
        return mTextView.getText().toString();
    }

    public void setText(String text){
        mTextView.setText(text);

        if (!LanguageUtils.isSimChinese(TGApplicationBase.getApplicationContext())){
            if (StringUtils.equalsIgnoreCase(text, ResourcesUtil.getString(R.string.device_hibernate))){
                mTextView.setVisibility(GONE);
            }
        }
    }

}
